import service from "./service/terrainrtsService";
import { getProjectManager } from "@/scripts/getProjectManager";
import loading from "./loading";


const terrainBaseUrl = () => {
  const objm = getProjectManager()
  return objm.terrainrtsManager.terrainRtsUrl.match(/^(https?:\/\/[^\/]+)/)?.[1]
}


/**
 * 获取系统配置
 */
export const reqGetSetting = () => {
  const getInfoData = service({
    url: `${terrainBaseUrl()}/system/setting/get`,
    method: 'get',

  })
  return getInfoData
}

// 切片服务列表
export const reqGetRecordList = (data: any) => {
  const getInfoData = service({
    url: `${terrainBaseUrl()}/ts/record/list`,
    method: 'post',
    data
  })
  return getInfoData
}

/**
 * 获取单个切片服务
 * @param {*} data
 * @returns
 */
export const reqGetOneTileService = (tileServiceName: any) => {
  const getInfoData = service({
    url: `${terrainBaseUrl()}/ts/info/${tileServiceName}`,
    method: 'get',
  })
  return getInfoData
}

// 查询高程蒙版
export const reqGetHeightMask = (data: any) => {
  const getInfoData = service({
    url: `${terrainBaseUrl()}/ts/heightmask/list`,
    method: 'post',
    data,
  })
  return getInfoData
}

// 添加高程蒙版
export const reqCreateHeightMask = (data: any) => {
  loading.showLoading("正在提交，请稍后...")
  const getInfoData = service({
    url: `${terrainBaseUrl()}/ts/heightmask/create`,
    method: 'post',
    data,
  })
  return getInfoData
}

// 查询水面蒙版
export const reqGetWaterMask = (data: any) => {
  const getInfoData = service({
    url: `${terrainBaseUrl()}/ts/watermask/list`,
    method: 'post',
    data,
  })
  return getInfoData
}

// 添加水面蒙版
export const reqCreateWaterMask = (data: any) => {
  loading.showLoading("正在提交，请稍后...")
  const getInfoData = service({
    url: `${terrainBaseUrl()}/ts/watermask/create`,
    method: 'post',
    data,
  })
  return getInfoData
}

// 查询裁剪多边形
export const reqGetClipPolygon = (data: any) => {
  const getInfoData = service({
    url: `${terrainBaseUrl()}/ts/clip/list`,
    method: 'post',
    data,
  })
  return getInfoData
}

// 添加裁剪多边形
export const reqCreateClipPolygon = (data: any) => {
  loading.showLoading("正在提交，请稍后...")
  const getInfoData = service({
    url: `${terrainBaseUrl()}/ts/clip/create`,
    method: 'post',
    data,
  })
  return getInfoData
}

// 获取shp中所有要素
export const reqGetShpFeatures = (data:any) => {  
  loading.showLoading("正在获取shp中的所有要素，请稍后...");
  const getInfoData = service({
    url: `${terrainBaseUrl()}/system/file/shp/features`,
    method: 'post',
    data,
  })
  return getInfoData
}

// 上传shp（zip格式）
export const upShpZip = (data:any) => {
  const getInfoData = service({
    url: `${terrainBaseUrl()}/system/file/upload/shpzip`,
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  return getInfoData;
};

// 上传shp
export const upShp = (data:any) => {
  const getInfoData = service({
    url: `${terrainBaseUrl()}/system/file/upload/shp`,
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  return getInfoData;
};